<?php

namespace app\hotel\controller;

use think\Controller;

class Room extends Controller
{
    public function _initialize()
    {
        // 继承父类
        parent::_initialize();
        $this->BusinessModel = model('Business.Business');
        $this->RoomModel = model('Hotel.Room');
        $this->CouponReceiveModel = model('Coupon.Receive');
    }

    // 列表
    public function index()
    {
        if ($this->request->isPost())
        {
            $page = $this->request->param('page', 1, 'trim');
            $keywords = $this->request->param('keywords', '', 'trim');

            $where = [];

            if(!empty($keywords))
            {
                $where['name'] = ['like', "%{$keywords}%"];
            }


            $list = $this->RoomModel->where($where)->order('id desc')->page("$page,10")->select();

            if ($list)
            {
                $this->success('', '', $list);
                exit;
            }
            else
            {
                $this->error('暂无数据');
                exit;
            }
        }
    }
    
    // 详情
    public function info()
    {
        if ($this->request->isPost())
        {
            $roomid = $this->request->param('roomid', 0, 'intval');

            $room = $this->RoomModel->find($roomid);

            if(!$room)
            {
                $this->error('酒店房间不存在');
                exit;
            }

            $this->success('', '', $room);
        }
    }
}
